package model;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.naming.NamingException;
import javax.sql.rowset.CachedRowSet;

import com.sun.rowset.CachedRowSetImpl;

import db.DbConnectionPool;
import db.DbException;
import forms.StudentForm;

public class DisciplineModel {
	
	private static String selectAllDiscipline = "SELECT * FROM disciplines";
	
	public static CachedRowSet getAllDiscipline() throws DbException {

		try {
			Connection conn = DbConnectionPool.getConnection();
			
			// Setup Query
			PreparedStatement pstmt = conn.prepareStatement(selectAllDiscipline);
			
			// Execute Query
			ResultSet rset = pstmt.executeQuery();

			CachedRowSet crset = new CachedRowSetImpl();
			crset.populate(rset);

			rset.close();
			pstmt.close();
			conn.close();

			return crset;
		} catch (SQLException ex) {
			throw new DbException(ex);
		} catch (NamingException ex) {
			throw new DbException(ex);
		}
	}
}
